package ru.kest.torrentwatchlist.web.transform;

import org.springframework.stereotype.Component;
import ru.kest.torrentwatchlist.entity.NnmTorrent;
import ru.kest.torrentwatchlist.entity.Torrent;
import ru.kest.torrentwatchlist.parsing.nnm.NNMTransformer;
import ru.kest.torrentwatchlist.web.model.TorrentBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Konstantin on 09.12.2014.
 */
@Component
public class TorrentTransformer {

    public List<TorrentBean> transformTorrents(List<Torrent> dbTorrents) {
        List<TorrentBean> result = new ArrayList<TorrentBean>();

        for(Torrent dbTorrent : dbTorrents) {
            result.add(transformTorrent(dbTorrent));
        }
        return result;
    }

    private TorrentBean transformTorrent(Torrent dbTorrent) {
        TorrentBean result = new TorrentBean();

        result.setTranslation(dbTorrent.getTranslation());
        result.setFormat(dbTorrent.getFormat());
        result.setSize(dbTorrent.getSize());
        result.setTitle(dbTorrent.getTitle());
        result.setUrl(dbTorrent.getUrl());
        result.setTorrentUrl(dbTorrent.getTorrentUrl());

        if (dbTorrent instanceof NnmTorrent) {
            // TO-DO temporary disabled
            NNMTransformer nnmTransformer = new NNMTransformer();
            nnmTransformer.transformNNMTorrent(result, (NnmTorrent) dbTorrent);
//            result.setLeechers("100");
//            result.setSeeders("100");
        }
        return result;
    }


}
